﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

using ECCIT;

namespace OgilvyOne.UKNow.Mobile.Model
{
    [Serializable]
    [DataContract]
    public class ModelList<T>
    {
        public ModelList() { }

        public ModelList(PagingParameter pagingParams, int totalRecordCount)
        {
            if (pagingParams == null) return;
            this.TotalCount = totalRecordCount;
            this.CurrentPageIndex = pagingParams.CurrentPageIndex;
            this.PageCount = (totalRecordCount % pagingParams.PageSize == 0) ? totalRecordCount / pagingParams.PageSize : totalRecordCount / pagingParams.PageSize + 1;
        }

        public ModelList(int pageSize, int currentPageIndex, int totalRecordCount)
        {
            this.TotalCount = totalRecordCount;
            this.CurrentPageIndex = currentPageIndex + 1; //currentPageIndex == 0 ? currentPageIndex + 1 : currentPageIndex;
            this.PageCount = (totalRecordCount % pageSize == 0) ? totalRecordCount / pageSize : totalRecordCount / pageSize + 1;
        }

        [DataMember(Name = "list")]
        public List<T> List { get; set; }

        [DataMember(Name = "total")]
        public int TotalCount { get; set; }

        [DataMember(Name = "page_count")]
        public int PageCount { get; set; }

        [DataMember(Name = "current_page")]
        public int CurrentPageIndex { get; set; }
    }
}
